import { fileURLToPath, URL } from 'url';
import { loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite';
import { ArcoResolver } from 'unplugin-vue-components/resolvers';
// import { createStyleImportPlugin } from 'vite-plugin-style-import'
// https://vitejs.dev/config/
export default  ({ mode }) => {
	const env = loadEnv(mode, process.cwd());
  return {
		base: env.VITE_BASE_URL, // 生产环境下的公共路径
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ArcoResolver()],
      }),
      Components({
        resolvers: [
          ArcoResolver({
            sideEffect: true
          })
        ]
      }),
      // createStyleImportPlugin({
      //   libs: [
      //     {
      //       libraryName: '@arco-design/web-vue',
      //       esModule: true,
      //       resolveStyle: (name) => {
      //         // css
      //         return `@arco-design/web-vue/es/${name}/style/css.js`
      //       },
      //     }
      //   ]
      // })
    ],
    resolve: {
      alias: [{ find: '@', replacement: fileURLToPath(new URL('./src', import.meta.url)) }],
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.vue', '.tsx', '.json'],
    },
    server: {
      proxy: {
        '/proxy': {
          target: env.VITE_HOST,
          rewrite: (path) => path.replace(/^\/proxy/, ''),
          changeOrigin: true,
        },
      },
    },
  }
}